package com.dongnam.quanly.common.dao;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Projections;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.dongnam.quanly.common.model.KhoHang;
import com.dongnam.quanly.common.model.NganHang;

public class NganHangDao extends ExtendedGenericDao<NganHang, String> {

	private static final Logger logger = LoggerFactory.getLogger(NganHangDao.class);

	public long findCountByFilters() {
		Criteria crit = getSession().createCriteria(getPersistentClass());
		return ((Number) crit.setProjection(Projections.rowCount()).uniqueResult()).longValue();
	}

	@SuppressWarnings("unchecked")
	public List<NganHang> findByFilters(int pageSize, int pageNumber, String sortField, String sortOrder) {

		Criteria crit = getSession().createCriteria(getPersistentClass());

		crit.setFirstResult(pageNumber * pageSize);
		crit.setMaxResults(pageSize);

		crit.setFirstResult(pageNumber * pageSize);
		crit.setMaxResults(pageSize);
		if (sortOrder != null && !sortOrder.equalsIgnoreCase("UNSORTED") && sortField != null) {
			if (sortOrder.equalsIgnoreCase("ASCENDING")) {
				crit.addOrder(Order.asc(sortField));
			} else {
				crit.addOrder(Order.desc(sortField));
			}
		}
		return crit.list();
	}

}
